package jp.tkym.labs.ws;

import java.io.IOException;

import org.eclipse.jetty.websocket.WebSocket.OnTextMessage;

class MyWebSocket implements OnTextMessage{
	private WebSocketMembers members = WebSocketMembers.getInstance();
	private Connection connection;
	
	public Connection getConnection() {
		return connection;
	}
	
	@Override
	public void onClose(int arg0, String arg1) {
		members.asSet().remove(this);
	}

	@Override
	public void onOpen(Connection arg0) {
		members.asSet().add(this);
	}

	@Override
	public void onMessage(String arg0) {
		try {
			for(MyWebSocket member : members.asSet())
				member.getConnection().sendMessage(arg0);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}